﻿using ProjScan.Tools;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEditor;
using UnityEngine;

namespace ProjScan.RecordManager.AssetData
{
    //
    // 摘要:
    //     引用资源数据 - Class81
    internal class ReferencedAssetData : AssetDataBase
    {
        public int DirectoryId
        {
            get;
            set;
        }

        protected string AssetName
        {
            get;
            set;
        }

        public Type AssetType
        {
            get;
            set;
        }

        public List<string> ReferenceList
        {
            get;
            set;
        }

        public object InstantiableAsset
        {
            get;
            set;
        }

        private string Path
        {
            get;
            set;
        }

        public ReferencedAssetData(int DirectoryId, UnityEngine.Object InstantiableAsset, List<string> ReferenceList)
        {
            Path = AssetDatabase.GetAssetPath(InstantiableAsset);
            this.DirectoryId = DirectoryId;
            AssetType = InstantiableAsset.GetType();
            AssetName = InstantiableAsset.name;
            this.InstantiableAsset = InstantiableAsset;
            this.ReferenceList = ReferenceList;
        }

        public override string GetCSVHeader()
        {
            return "AssetName,DirID,NumberOfReferences";
        }

        public override string GetInfo()
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append(ToolsHelper.QuoteString(AssetName));
            stringBuilder.Append(',');
            stringBuilder.Append(DirectoryId);
            stringBuilder.Append(',');
            stringBuilder.Append(ReferenceList.Count);
            return stringBuilder.ToString();
        }

        public override void Reset()
        {
            InstantiableAsset = null;
        }

        public override string GetAssetPath()
        {
            return Path;
        }

        public override string GetFileAssetPath()
        {
            return Path;
        }
    }
}